#include "Window.h"
using namespace pg1;
Window::Window(HINSTANCE hInstance){

	hWnd = NULL;
	this->hInstance = hInstance;
}
Window::~Window(){
	if(hWnd) DestroyWindow(hWnd);
}

bool Window::createWindows(unsigned int weidth, unsigned int heigth){

	this->height = heigth + 30;
	this->width = weidth + 8;

	WNDCLASS kWC;

	memset(static_cast<void *> (&kWC), 0, sizeof(WNDCLASS));
	kWC.style = CS_HREDRAW | CS_VREDRAW;
	kWC.lpfnWndProc = (WNDPROC) WndProc;
	kWC.hInstance = hInstance;
	kWC.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
	kWC.lpszClassName = "Engine";
 
    if(!RegisterClass(&kWC))
		return false;
	wndName="Engine Avena Daniel Klein Fernando";
    hWnd = CreateWindow("Engine",        // name of window class 
		wndName.c_str(),            // title-bar string 
		WS_VISIBLE | WS_OVERLAPPEDWINDOW, // top-level window 
        CW_USEDEFAULT,       // default horizontal position 
        CW_USEDEFAULT,       // default vertical position 
        weidth + 8,       // default width 
        heigth + 30,       // default height 
        NULL,         // no owner window 
        NULL,        // use class menu 
        hInstance,           // handle to application instance 
        NULL);      // no window-creation data 
 
    if (!hWnd) 
        return false; 
	
	//ShowWindow(hWnd, nCmdShow); 
	UpdateWindow(hWnd); 
	
    return true; 
}
HWND Window::getHWnd(){
	
	return hWnd;
}

bool Window::setWindowName(std::string p){
 SetWindowText(hWnd,p.c_str());
 return true;
}
std::string Window::getWindowName(){
 return wndName;
}
int Window::getHeight(){
	return height;
}

int Window::getWidth(){
	return width; 
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, 
						 WPARAM wParam, LPARAM lParam){
	
	switch (message) {

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}